package com.sf.tools;

import com.sf.domain.Refund;
import com.sf.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class AppointmentTools {
    @Autowired
    private AppointmentService appointmentService;
    @Tool(name="申请退款", value = "让用户确认所有退款信息，用户确认后再进行申请退款。")
    public String applyRefund(Refund refund){
        //查找数据库中是否包含对应的退款记录
        Refund refundInDB = appointmentService.getOne(refund);
        if(refundInDB == null){
            refund.setId(null);//防止大模型幻觉设置了id
            if(appointmentService.save(refund)){
                return "预约退款成功";
            }else{
                return "预约失败";
            }
        }
        return "您已经预约过退款";
    }
    @Tool(name="取消退款申请", value = "当用户需要取消退款的时候，先让用户提供申请退款一样的参数，根据参数，查询退款申请是否存在，如果存在则删除退款申请记录并返回取消退款成功，否则返回取消退款失败")
    public String cancelApplyRefund(Refund refund){
        Refund refundInDB = appointmentService.getOne(refund);
        if(refundInDB != null){
        //删除预约记录
            if(appointmentService.removeById(refundInDB.getId())){
                return "取消退款成功";
            }else{
                return "取消退款失败";
            }
        }
        //取消失败
        return "您没有退款申请记录，请核对申请退款信息";
    }
}
